<template>
    <div>
        <van-field label='名字' v-model="name" />
        <van-field label='参数' v-model="params"/>
        选择分类<reply :data='cates'/>
        <van-button @click="add" color="linear-gradient(to right, #ff6034,#7232dd)">添加</van-button>
    </div>
</template>

<script>
import reply from '@/components/p7/reply'
    export default {
        components:{
            'reply':reply
                
        },
        data(){
            return{
                name:'',
                params:'',
                pid:0,
                cates:{}
            }
        },
        methods:{
            add(){
                if(this.params){
                    this.params = JSON.stringify(this.params)
                }
                if(localStorage.getItem('pid')){
                    this.pid = localStorage.getItem('pid')
                }
                let data = {'name':this.name,'pid':this.pid,'params':this.params}
                this.$axios.post('cateM',data).then(res=>{
                    alert('添加成功')
                    this.get_list()
                })
            },
            get_list(){
                this.$axios.get('cateM').then(res=>{
                    this.cates = {'id':0,'name':'111','son':res.data.list}
                })
            }
        },
        mounted(){
            this.get_list()
        }
    }
</script>

<style scoped>

</style>